package com.yykj.common.config;

import org.hibernate.HibernateException;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.ImplicitEntityNameSource;
import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy;

public class LocalNamingStrategy extends SpringImplicitNamingStrategy {

	private static final String PREFIX = "core_";

	public Identifier determinePrimaryTableName(ImplicitEntityNameSource source) {
		if (source == null) {
			throw new HibernateException("Entity naming information was not provided.");
		}
		String tableName = transformEntityName(source.getEntityNaming());
		if (tableName == null) {
			throw new HibernateException(
					"Could not determine primary table name for entity");
		}
		tableName = PREFIX + tableName;
		return toIdentifier(tableName, source.getBuildingContext());
	}

}
